<template>
  <el-card class="box">
    <!-- 查询区域 -->
    <el-form :inline="true" :model="Form" class="demo-form-inline">
      <el-form-item label="工单号">
        <el-input v-model="Form.number" placeholder="请输入工单号"></el-input>
      </el-form-item>
      <el-form-item label="标题">
        <el-input v-model="Form.title" placeholder="请输入标题"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="Search_data(Form)">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格区域 -->
    <el-table :data="sys_search" border stripe style="width: 100%">
      <el-table-column
        fixed
        type="index"
        label="#"
        width="80"
      ></el-table-column>
      <el-table-column
        prop="number"
        label="工单号"
        width="120"
      ></el-table-column>
      <el-table-column prop="title" label="标题" width="200"></el-table-column>
      <el-table-column
        prop="difficulty"
        label="难度"
        sortable
        align="center"
        width="180"
      >
        <template v-slot="scope">
          <el-rate v-model="scope.row.difficulty" disabled></el-rate>
        </template>
      </el-table-column>
      <el-table-column prop="schedule" label="进度" sortable>
        <template v-slot="scope">
          <el-progress
            :percentage="scope.row.schedule"
            :status="status(scope.row.schedule)"
          ></el-progress>
        </template>
      </el-table-column>
      <el-table-column
        prop="receive"
        label="归属"
        width="120"
      ></el-table-column>
      <el-table-column prop="submit" label="发布" width="100"></el-table-column>
      <el-table-column prop="date" label="发布日期"></el-table-column>
      <el-table-column prop="status" label="状态" sortable width="100">
        <template v-slot="scope">
          <el-tag type="success" size="small" v-if="scope.row.status == 0"
            >待接取</el-tag
          >
          <el-tag type="danger" size="small" v-else-if="scope.row.status == 1"
            >进行中</el-tag
          >
          <el-tag type="info" size="small" v-else>已完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleClick(scope.row)"
            >查看</el-button
          >
          <el-button type="text" size="small" @click="edit(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 编辑框 -->
    <el-dialog
      title="编辑"
      :visible.sync="dialogVisible"
      width="30%"
      center
      :before-close="handleClose"
    >
      <el-form :model="EditForm">
        <el-form-item label="标题" label-width="80px">
          <el-input v-model="EditForm.title" width="100px"></el-input>
        </el-form-item>
        <el-form-item label="难度" label-width="80px">
          <el-rate v-model="EditForm.difficulty"></el-rate>
        </el-form-item>
        <el-form-item label="进度" label-width="80px">
          <el-slider v-model="EditForm.schedule" :step="10"> </el-slider>
        </el-form-item>
        <el-form-item label="归属" label-width="80px">
          <el-select v-model="EditForm.receive" placeholder="请选择归属者">
            <el-option label="月老" value="月老"></el-option>
            <el-option label="李白" value="李白"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发布" label-width="80px">
          <el-select v-model="EditForm.submit" placeholder="请选择发布者">
            <el-option label="chalk" value="chalk"></el-option>
            <el-option label="张三" value="张三"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发布日期" label-width="80px">
          <el-date-picker
            v-model="EditForm.date"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态" label-width="80px">
          <el-radio-group v-model="EditForm.status">
            <el-radio label="0">待接取</el-radio>
            <el-radio label="1">进行中</el-radio>
            <el-radio label="2">已完成</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      EditForm: {},
      Form: {
        number: '',
        title: ''
      },
      search: {
        number: '',
        title: ''
      },
      sys: [
        // 字符串是字符串，数字是数字，不能混淆
        {
          id: '1',
          number: '10001',
          title: '寻找有缘人',
          content: '寻找有缘人内容',
          difficulty: 5,
          schedule: 50,
          receive: '月老',
          submit: 'chalk',
          date: '2020/2/2',
          status: '0'
        },
        {
          id: '2',
          number: '10002',
          title: '寻找倒霉人',
          content: '寻找倒霉人内容',
          difficulty: 3,
          schedule: 100,
          receive: '月老',
          submit: 'chalk',
          date: '2020/2/3',
          status: '1'
        }
      ]
    }
  },
  methods: {
    // 进度条
    status(e) {
      if (e === 100) {
        return 'success'
      }
    },
    Search_data(e) {
      this.search = e
    },
    // 查看按钮点击事件 路由跳转
    handleClick(e) {
      this.$router.push({ name: 'TaskDetails', params: { details: e } })
    },
    // 编辑按钮点击事件
    edit(e) {
      this.EditForm = e
      this.dialogVisible = true
    },
    // 编辑对话框关闭事件
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    }
  },
  computed: {
    sys_search() {
      return this.sys.filter(data => (data.number.toLowerCase().includes(this.search.number.toLowerCase()) && data.title.toLowerCase().includes(this.search.title.toLowerCase())))
    }
  }
}
</script>
<style lang="less" scoped>
.el-card.box {
  height: 100%;
  background: url(../assets/img/cen.jpg) no-repeat center #fff;
  background-size: contain;
  span {
    font-size: auto;
  }
  .el-dialog {
    text-align: left;
    .el-rate {
      display: inline-block;
    }
  }
}
</style>
